home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 037a / tmouse.zip / TMOUSE.DOC next >
Text File  |  1991-12-01  |  16KB  |  439 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                                   Turbo Mouse
  7.                                   Version 2.1
  8.                    Turbo Pascal Interface to Microsoft Mouse
  9.            (C) Copyright 1991, Andrew Verba, All Rights Reserved
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.                                TABLE OF CONTENTS
  24.  
  25.             I.   Introduction .................................. 2
  26.             II.  Included Files ................................ 2
  27.             III. Function and Procedure Overview ............... 3
  28.             IV.  Function and Procedure Details ................ 5
  29.  
  30.  
  31.                                       -2-
  32.  
  33.  
  34. Introduction
  35. ------------
  36.    These routines are being distributed as an aid to the development of
  37. Turbo Pascal programs using the Microsoft mouse.  The mouse comes with a
  38. program that is accessed via BASIC but it is not accessable from Turbo Pascal.
  39.    The routines supplied by Microsoft are also cryptic.  Who can understand a
  40. statement like:
  41.                 CALL MOUSE(M1%,M2%,M3%,M4%) ?????
  42. Hopefully the functions and procedures presented here are easier to understand
  43. and use, leading to faster development and simpler debugging than possible
  44. with the BASIC call function.
  45.    The calls to the Turbo Mouse routines are more straight forward.  For
  46. instance the BASIC code to see if the mouse hardware and driver are installed
  47. is:
  48.                 10 DEF SEG=0
  49.                 20 MSEG=256*PEEK(51*4+3)+PEEK(51*4+2)
  50.                 30 MOUSE=256*PEEK(51*4+1)+PEEK(51*4+2)
  51.                 40 IF MSEG OR (MOUSE-2) THEN 60
  52.                 50 PRINT "Mouse not installed":END
  53.                 60 DEF SEG=MSEG
  54.                 70 M1%=0
  55.                 80 CALL MOUSE(M1%,M2%,M3%,M4%)
  56.                 90 IF NOT(M1%) THEN PRINT "Mouse not installed":END
  57.  
  58. Not the clearest code. But with Turbo Mouse :
  59.  
  60.                 if not mouse_installed
  61.                   writeln('Mouse not installed');
  62.  
  63. It's hard to beat.
  64.  
  65.        If you are a programmer and find this type of software
  66.        helpful, time-saving, as well as cutting redundancy
  67.        in your code; donate. Send 2 dollars with your name
  68.        and address to:
  69.                 Andrew Verba
  70.                 1001 Eagle Rd.
  71.                 Wayne, PA, 19087
  72.        You will recieve an account at Software Inc BBS. This BBS
  73.        is full of reliable, expandable code that you can use and
  74.        incorporate in almost any of your projects.
  75.        And help fight overpriced commercial software, use shareware
  76.        instead!
  77.  
  78. Included Files
  79. -------- -----
  80.    There are two files making up Turbo Mouse version 2.1.
  81.  
  82.           TMOUSE.DOC    This document.
  83.  
  84.           TMOUSE.PAS    This file contains the functions and procedures making
  85.                         up Turbo Mouse.  In order to use it you must include
  86.                         it before your programs code. Uses TMOUSE; is fine.
  87.  
  88.           TMOUSE.TPU    This is the unit file already compiled.
  89.  
  90.  
  91.  
  92.                                       -3-
  93.  
  94.  
  95. Function and Procedure Overview
  96. -------- --- --------- --------
  97.    Following is a listing of the functions and procedures followed by a brief
  98. description of each.  Details on the routines and the variables involved can
  99. be found on page 5.
  100.  
  101.    Functions
  102.    ---------
  103.        function mouse_installed : boolean;
  104.           Return true if mouse driver and hardware are installed.  Reset mouse
  105.           to default settings.
  106.  
  107.        function button_pressed(button : integer) : boolean;
  108.           Return true if the button is being held down.
  109.  
  110.        function number_of_presses(button : integer) : integer;
  111.           Return the number of times that the button has been pressed since
  112.           the last time that this function was called.
  113.  
  114.        function number_of_releases(button : integer) : integer;
  115.           Return the number of times that the button has been released since
  116.           the last time that this function was called.
  117.  
  118.  
  119.    Procedures
  120.    ----------
  121.        procedure show_cursor;
  122.           Make the cursor visible.
  123.  
  124.        procedure hide_cursor;
  125.           Make the cursor invisible.
  126.  
  127.        procedure get_cursor_position(var horizontal, vertical : integer);
  128.           Get the position of the cursor on the screen.
  129.  
  130.        procedure set_cursor_position(horizontal, vertical : integer);
  131.           Move the cursor to the specified position on the screen.
  132.  
  133.        procedure set_min_max_horiz(minimum, maximum : integer);
  134.           Set the minimum and maximum horizontal positions of the cursor.
  135.  
  136.        procedure set_min_max_vert(minimum, maximum : integer);
  137.           Set the minimum and maximum vertical positions of the cursor.
  138.  
  139.        procedure set_graphics_cursor(hot_spot_x, hot_spot_y : integer;
  140.                                      var cursor : cursor_array);
  141.           Pass a custom cursor to the mouse hardware.
  142.  
  143.        procedure read_counters(var horizontal, vertical : integer);
  144.           Read the horizontal and vertical mickey count since the last call
  145.           to this procedure.
  146.  
  147.        procedure user_subroutine(mask, subroutine_segment, subroutine_offset
  148.                                  : integer);
  149.           Allows a branch to the specified subroutine according to the
  150.           conditions in the call mask.
  151.  
  152.  
  153.  
  154.                                       -4-
  155.  
  156.  
  157.    Procedures (cont.)
  158.    ----------
  159.        procedure light_pen_on;
  160.           Enables light pen emulation by the mouse.
  161.  
  162.        procedure light_pen_off;
  163.           Disables light pen emulation by the mouse.
  164.  
  165.        procedure set_pixel_ratio(horizontal_ratio, vertical_ratio : integer);
  166.           Sets the sensitivity of the mouse.  Number of rotations per 8
  167.           pixels.
  168.  
  169.        procedure set_text_cursor(bottom_line, top_line : integer);
  170.           Select the hardware text cursor and the scan lines used.
  171.  
  172.  
  173.                                       -5-
  174.  
  175.  
  176. Function and Procedure Details
  177. -------- --- --------- -------
  178.    The following is the full information on the functions and procedures in
  179. Turbo Mouse.  It is not intended as a tutorial on Turbo Pascal.  It is assumed
  180. that the user of these routines understands the difference between functions
  181. and procedures.  There is only one user defined variable type.  It is an array
  182. that is used to pass the graphics cursor to the mouse.  It is a simple array
  183. of integers and it is defined at the beginning of MMOUSE.PAS.
  184.    It is a good idea to read the section of the Microsoft mouse manual called
  185. "Mouse Interface and System Calls".
  186.  
  187.  
  188.    Functions
  189.    ---------
  190.  
  191.  
  192.                       function mouse_installed : boolean;
  193.  
  194.    Return true if mouse driver and hardware are installed.  Reset mouse to
  195. default settings:
  196.        centers cursor on the screen
  197.        sets the graphics cursor to the arrow with a hotspot of -1, -1
  198.        sets the text cursor as an inverting box
  199.        clears the user defined call mask
  200.        enables light pen emulation
  201.        sets the rotation per pixel ratio: 8 to 8 for horizontal
  202.                                           16 to 8 for vertical
  203.        sets the minimum and maximum cursor positions to the full screen :
  204.                 horizontal -> 0 to 639
  205.                 vertical   -> 0 to 199
  206.    Example :
  207.        if not mouse_installed
  208.           writeln('Mouse not installed');
  209.  
  210.  
  211.  
  212.              function button_pressed(button : integer) : boolean;
  213.  
  214.    Return true if the button is being held down.  The variable "button" should
  215. be either 0 for the left button or 1 for the right button.  If any other
  216. number is passed it is treated as a 1.
  217.  
  218.    Example :
  219.        if button_pressed(0) then
  220.           writeln('Why don't you let go of the left button')
  221.  
  222.  
  223.  
  224.             function number_of_presses(button : integer) : integer;
  225.  
  226.    Return the number of times that the button has been pressed since the last
  227. time that this function was called.  Again button should be 0 for the left
  228. button and 1 for the right button.
  229.  
  230.    Example :
  231.        writeln('Press the right button to plot a point');
  232.        while number_of_presses(1) = 0 do ;
  233.        plot(x, y, color);
  234.  
  235.  
  236.                                       -6-
  237.  
  238.  
  239.            function number_of_releases(button : integer) : integer;
  240.  
  241.    Return the number of times that the button has been released since the last
  242. time that this function was called.  Button = 0 -> left button.  Button = 1 ->
  243. right button.
  244.  
  245.    Example :
  246.        writeln('The left button has been released ',number_of_releases(0),
  247.                'times.');
  248.  
  249.  
  250.  
  251.    Procedures
  252.    ----------
  253.                             procedure show_cursor;
  254.  
  255.    Make the cursor visible.  This procedure takes no parameters.  It just
  256. turns the cursor on.  Always turn the cursor off before modifying the portion
  257. of the screen containing the cursor.  This will prevent the corruption
  258. of the display.
  259.  
  260.    Example :
  261.        show_cursor;
  262.  
  263.  
  264.  
  265.                             procedure hide_cursor;
  266.  
  267.    Make the cursor invisible.  This procedure takes no parameters.  It just
  268. turns the cursor off.  Even though the cursor is off, it still tracks the
  269. movement of the mouse.  Always turn the cursor off before modifying the
  270. portion of the screen containing the cursor.  This will prevent the corruption
  271. of the display.
  272.  
  273.    Example :
  274.        hide_cursor;
  275.        plot(x, y, color);
  276.        show_cursor;
  277.  
  278.  
  279.  
  280.       procedure get_cursor_position(var horizontal, vertical : integer);
  281.  
  282.    Get the position of the cursor on the screen.  The cursor position is
  283. returned in the parameters horizontal and vertical.  The position is always
  284. within the range of the minimum and maximum values set by the set_min_max
  285. procedures.
  286.  
  287.    Example :
  288.        get_cursor_position(x, y);
  289.        gotoxy(x, y);
  290.        write('I hope this is where you wanted it.');
  291.  
  292.  
  293.                                       -7-
  294.  
  295.  
  296.         procedure set_cursor_position(horizontal, vertical : integer);
  297.  
  298.    Move the cursor to the specified position on the screen.  The values of
  299. horizontal and vertical must be within the ranges specified by the set_min_max
  300. procedures.
  301.  
  302.    Example :
  303.        set_cursor_position(25, 50);
  304.  
  305.  
  306.  
  307.            procedure set_min_max_horiz(minimum, maximum : integer);
  308.  
  309.    Set the minimum and maximum horizontal positions of the cursor.  Motion of
  310. the cursor is restricted to the left and right limits set by minimum and
  311. maximum.  If the cursor is outside of the limits when the call is made, it is
  312. moved to just inside the bounds.
  313.  
  314.    Example :
  315.        set_min_max_horiz(0, 200); { restrict the action to the left side of
  316.                                     the screen. }
  317.  
  318.  
  319.  
  320.             procedure set_min_max_vert(minimum, maximum : integer);
  321.  
  322.    Set the minimum and maximum vertical positions of the cursor.  Motion of
  323. the cursor is restricted the the upper and lower limits set by minimum and
  324. maximum.  Again if the cursor is outside of the limits at the time of the
  325. call, it will be moved just inside the limit.
  326.  
  327.    Example :
  328.        set_min_max_vert(50, 150); { restrict motion to the middle of the
  329.                                     screen. }
  330.  
  331.  
  332.  
  333.         procedure set_graphics_cursor(hot_spot_x, hot_spot_y : integer;
  334.                                       var cursor : cursor_array);
  335.  
  336.    Pass a custom cursor to the mouse hardware.  The hot spots are the active
  337. part of the cursor (the part that is actually pointing).  They must be in the
  338. range of -16 to 16.  The cursor array is an array[0..31] of integer containing
  339. both the screen mask and the cursor mask.  The following example is an
  340. adaptation of the arrow pointer shown in the Microsoft mouse manual.
  341.  
  342.    Example :
  343.        const
  344.        cursor : cursor_array=($FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,
  345.                               $FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,
  346.                               $8000,$E000,$F800,$FE00,$D800,$0C00,$0600,$0300,
  347.                               $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000);
  348.        hot_spot_x : integer = 0;
  349.        hot_spot_y : integer = 0;
  350.        set_graphics_cursor(hot_spot_x, hot_spot_y, cursor);
  351.  
  352.  
  353.                                       -8-
  354.  
  355.  
  356.          procedure read_counters(var horizontal, vertical : integer);
  357.  
  358.    Read the horizontal and vertical mickey count since the last call to this
  359. procedure.  A mickey is equivalent to about 1/100th of an inch.  A positive
  360. horizontal value signifies motion to the right.  A positive vertical value
  361. signifies motion towards the bottom of the screen.  The count is set to zero
  362. by this call.
  363.  
  364.    Example :
  365.        if horiz <> 0 then
  366.           writeln('You have moved ', horiz / 100, 'inches to the right.')
  367.        else
  368.           writeln('You have moved ', horiz / 100, 'inches to the left.');
  369.  
  370.  
  371.  
  372.      procedure user_subroutine(mask, subroutine_segment, subroutine_offset
  373.                                : integer);
  374.  
  375.    Allows a branch to the specified subroutine according to the conditions in
  376. the call mask.  The mask is an integer that defines the conditions that will
  377. cause a branch to the user defined subroutine.  Only bits 0 through 4 are used
  378. and they are defined as follows:
  379.              Bit              Condition
  380.               0                  cursor position is changed
  381.               1                  left button is pressed
  382.               2                  left button is released
  383.               3                  right button is pressed
  384.               4                  right button is released
  385. Set the corresponding bit or bits in the mask using an integer corresponding
  386. to the bit positions that you want to set to 1.
  387.    Control can be passed to a procedure or function by using the CSEG function
  388. for the subroutine_segment and ofs(function_name) for the subroutine_offset.
  389. Control is passed back to the point where the interrupt occurred.
  390.  
  391.    Example :
  392.        mask = 10; { turn on bits 1 and 3.  Binary -> 01010 }
  393.        user_subroutine(mask, cseg, ofs(button_hit));
  394.  
  395.  
  396.  
  397.                             procedure light_pen_on;
  398.  
  399.    Enables light pen emulation by the mouse.  The pen is down when both both
  400. buttons are down, and up when both are up.  Now if only Turbo Pascal had light
  401. pen functions like BASIC does this would be useful.  Maybe I'll figure
  402. something out for future versions.  For now you are on your own.  This is the
  403. default state after resetting the mouse.
  404.  
  405.  
  406.  
  407.                            procedure light_pen_off;
  408.  
  409.    Disables light pen emulation by the mouse.  See light_pen_on.
  410.  
  411.  
  412.                                       -9-
  413.  
  414.  
  415.     procedure set_pixel_ratio(horizontal_ratio, vertical_ratio : integer);
  416.  
  417.    Sets the sensitivity of the mouse.  Number of mickeys per 8 pixels. A
  418. Mickey is about 1/100th of an inch of motion by the mouse.  The defeault
  419. values are 8 mickeys horizontally per 8 pixels horizontally and 16 mickeys
  420. vertically for 8 pixels vertically.
  421.  
  422.    Example :
  423.        set_pixel_ratio(1, 2);  { The cursor will really fly with this setting }
  424.  
  425.  
  426.  
  427.           procedure set_text_cursor(bottom_line, top_line : integer);
  428.  
  429.    Select the hardware text cursor and the scan lines used.  Bottom_line
  430. contains the line number of first scan line and top_line the upper line.
  431. Top_line should always be greater than or equal to bottom_line.  On the CGA
  432. the line numbers range from 0 to 7 with 0 being the lowest line and 7 the
  433. uppermost.  On the MDA the line numbers range from 0 to 11 in the same manner.
  434.  
  435.    Example :
  436.        set_text_cursor(0, 4);  { set a text cursor that is about one half the
  437.                                  height of the character box. }
  438.  
  439.